home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1995 May / PC Answers CD-ROM 7 (Future Publishing) (May 1995).iso / vbits / code / robinson / passarry.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-12-05  |  5.8 KB  |  206 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00808000&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Array to Excel"
  6.    ClientHeight    =   5565
  7.    ClientLeft      =   1110
  8.    ClientTop       =   1485
  9.    ClientWidth     =   5850
  10.    ClipControls    =   0   'False
  11.    Height          =   5970
  12.    Icon            =   PASSARRY.FRX:0000
  13.    Left            =   1050
  14.    LinkTopic       =   "Form1"
  15.    MaxButton       =   0   'False
  16.    ScaleHeight     =   5565
  17.    ScaleWidth      =   5850
  18.    Top             =   1140
  19.    Width           =   5970
  20.    Begin TextBox Text1 
  21.       Height          =   345
  22.       Left            =   150
  23.       TabIndex        =   3
  24.       Top             =   585
  25.       Width           =   2130
  26.    End
  27.    Begin CommandButton Command1 
  28.       Caption         =   "Send Data to Excel"
  29.       Height          =   495
  30.       Left            =   2910
  31.       TabIndex        =   2
  32.       Top             =   1800
  33.       Width           =   2415
  34.    End
  35.    Begin OLE OLE1 
  36.       BackColor       =   &H00C0C0C0&
  37.       Class           =   "Excel.Chart.5"
  38.       fFFHk           =   -1  'True
  39.       Height          =   3075
  40.       Left            =   75
  41.       SizeMode        =   1  'Stretch
  42.       TabIndex        =   1
  43.       Top             =   2445
  44.       Width           =   5685
  45.    End
  46.    Begin Grid Grid1 
  47.       Cols            =   5
  48.       Height          =   1485
  49.       HighLight       =   0   'False
  50.       Left            =   2415
  51.       Rows            =   6
  52.       TabIndex        =   0
  53.       Top             =   105
  54.       Width           =   2895
  55.    End
  56.    Begin Image Image1 
  57.       Height          =   705
  58.       Left            =   630
  59.       Top             =   1275
  60.       Width           =   795
  61.    End
  62.    Begin Label Label1 
  63.       AutoSize        =   -1  'True
  64.       BackColor       =   &H8000000F&
  65.       BackStyle       =   0  'Transparent
  66.       Caption         =   "Enter Data:"
  67.       Height          =   195
  68.       Left            =   150
  69.       TabIndex        =   4
  70.       Top             =   345
  71.       Width           =   990
  72.    End
  73. Option Explicit
  74. Dim xlSheet As Object
  75. Dim R As Object
  76. Dim sOldValue As String
  77. Sub Command1_Click ()
  78.     Dim iRow As Integer
  79.     Dim iCol As Integer
  80.     Dim x As Integer
  81.     Dim y As Integer
  82.     Dim ArrStr As String
  83.     Const HOURGLASS = 11
  84.     Const DEFAULT = 0
  85.     Const OLE_CREATE_EMBED = 0
  86.     Const OLE_ACTIVATE = 7
  87.     Screen.MousePointer = HOURGLASS
  88.     'create an embedded object in the OLE control
  89.     OLE1.Action = OLE_CREATE_EMBED
  90.     OLE1.Action = OLE_ACTIVATE
  91.     DoEvents
  92.     'if there are 0 worksheets, add one
  93.     If OLE1.Object.Parent.Worksheets.count = 0 Then
  94.       OLE1.Object.Parent.Worksheets.Add
  95.     End If
  96.     'use a range object the size of the grid: 5 rows x 4 cols
  97.     Set xlSheet = OLE1.Object.Parent.Worksheets(1)
  98.     Set R = xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(6, 5))
  99.         x = 1
  100.         y = 1
  101.         ArrStr = "={"
  102.         For x = 0 To grid1.Rows - 1
  103.           grid1.Row = x
  104.           For y = 0 To grid1.Cols - 1
  105.             grid1.Col = y
  106.             If y > 0 And x > 0 Then
  107.               ArrStr = ArrStr + grid1.Text + ","
  108.             Else
  109.               ArrStr = ArrStr + """" + grid1.Text + ""","
  110.             End If
  111.           Next y
  112.           Mid$(ArrStr, Len(ArrStr), 1) = ";"
  113.         
  114.         Next x
  115.         
  116.         Mid$(ArrStr, Len(ArrStr), 1) = "}"
  117.         On Error Resume Next
  118.         R.FormulaArray = ArrStr
  119.         If Err Then
  120.             ' Debug.Print Arrstr
  121.             MsgBox "Too Long: " + CStr(Len(ArrStr))
  122.         Else
  123.             R.Copy
  124.             R.PasteSpecial -4163
  125.             xlSheet.Application.CutCopyMode = False
  126.         End If
  127.       
  128.       OLE1.Object.Parent.Charts(1).Activate
  129.       R.Parent.Parent.ActiveChart.ChartWizard R
  130.       
  131.       Screen.MousePointer = DEFAULT
  132. End Sub
  133. Sub Form_Load ()
  134.     Dim x As Integer, y As Integer, z As Integer
  135.     'set the icon
  136.     Image1.Picture = Form1.Icon
  137.     'set the column headings: Col 0
  138.     x = 0
  139.     y = 1
  140.     grid1.Col = x
  141.     grid1.Row = y
  142.     grid1.Text = "1990"
  143.     grid1.Row = y + 1
  144.     grid1.Text = "1991"
  145.     grid1.Row = y + 2
  146.     grid1.Text = "1992"
  147.     grid1.Row = y + 3
  148.     grid1.Text = "1993"
  149.     grid1.Row = y + 4
  150.     grid1.Text = "1994"
  151.     'set the row headings: row 0
  152.     x = 1
  153.     y = 0
  154.     grid1.Col = x
  155.     grid1.Row = y
  156.     grid1.Text = "Q1"
  157.     grid1.Col = x + 1
  158.     grid1.Text = "Q2"
  159.     grid1.Col = x + 2
  160.     grid1.Text = "Q3"
  161.     grid1.Col = x + 3
  162.     grid1.Text = "Q4"
  163.     'fill in the values of the grid
  164.     For x = 1 To grid1.Cols - 1
  165.       grid1.Col = x
  166.       For y = 1 To grid1.Rows - 1
  167.         grid1.Row = y
  168.         z = z + 200
  169.         grid1.Text = Trim$(Str$(z))
  170.       Next y
  171.     Next x
  172.     grid1.Refresh
  173.     Text1.Text = grid1.Text
  174.     sOldValue = grid1.Text
  175. End Sub
  176. Sub Grid1_KeyPress (KeyAscii As Integer)
  177.   If KeyAscii > 31 Then
  178.     Text1.Text = Text1.Text + Chr(KeyAscii)
  179.   End If
  180. End Sub
  181. Sub Grid1_KeyUp (KeyCode As Integer, Shift As Integer)
  182.     Const KEY_F2 = &H71
  183.     Const KEY_ESCAPE = &H1B
  184.     Select Case KeyCode
  185.       Case KEY_F2
  186.         Text1.SelStart = 0
  187.         If Len(Text1.Text) > 0 Then
  188.           Text1.SelLength = Len(Text1.Text)
  189.         End If
  190.         Text1.SetFocus
  191.       Case KEY_ESCAPE
  192.         Text1.Text = sOldValue
  193.     End Select
  194. End Sub
  195. Sub Grid1_RowColChange ()
  196.   Text1.Text = grid1.Text
  197.   sOldValue = Text1.Text
  198. End Sub
  199. Sub Text1_Change ()
  200.   grid1.Text = Text1.Text
  201. End Sub
  202. Sub Text1_KeyPress (KeyAscii As Integer)
  203.     Const KEY_RETURN = &HD
  204.     If KeyAscii = KEY_RETURN Then grid1.SetFocus
  205. End Sub
  206.